local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
local CallBackManager = ClientOHOH.load.CallBackManager();

local TweenService = game:GetService("TweenService")
local OY=0
local H=-150
local T=2
local TextColor3=Color3.new(1, 1, 1)
local TextSize=30
local DT=3
local tweenSpeed = 1

function M.new()
	return M();
end;

function M.ctor(self)--构造函数
	M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.GlobalTipGui"),10);
	
	--M.super.ctor(self, ClientOHOH:GetPath_Loop("ImageTip",self.main_inst));
	self.ImageTip=ClientOHOH:GetPath_Loop("ImageTip",self.main_inst)
	self.ImageTip.Visible=false
	self.main_inst.Enabled=true
end;

function M.dtor(self)--析构函数
	M.super.dtor(self);
end;

-- function M.OnShow2(self,text,tc,ts,pos,dlt,image) --tc,ts,pos,dlt 颜色，大小，位置 显示时间
		
-- 	local tpos=UDim2.new(0.5, 0, 0.5,OY)
-- 	local anchor=Vector2.new(0.5, 0.5)
-- 	local tsize=UDim2.new(0.85, 0, 0.08, 0)
	
-- 	local t= Instance.new("TextLabel")
-- 	t.Parent=self.main_inst
-- 	t.AnchorPoint=anchor
-- 	t.Position=tpos
-- 	t.Size=tsize
-- 	t.TextScaled = true
-- 	t.Text=text
-- 	t.BackgroundTransparency=1
-- 	t.TextStrokeTransparency=0
-- 	t.RichText=true
-- 	--print("guid:",text,tc,ts,pos,dlt)
-- 	if tc then		
-- 		--print(typeof(tc),tc)
-- 		if typeof(tc)=="table" then
-- 			t.TextColor3=Color3.new(tc[1],tc[2],tc[3])
-- 		else
-- 			t.TextColor3=tc
-- 		end

-- 	else
-- 		t.TextColor3=TextColor3
-- 	end

-- 	if ts then
-- 		t.TextSize=ts
-- 	else
-- 		t.TextSize=TextSize
-- 	end

-- 	if pos then
-- 		local sp=workspace.CurrentCamera:WorldToScreenPoint(pos)
-- 		t.Position=UDim2.new(0,sp.X,0,sp.Y)
-- 		local dt=DT
-- 		if dlt then
-- 			dt=dlt
-- 		end
-- 		delay(dt,function()
-- 			t:Destroy()
-- 		end)
-- 	else
-- 		t:TweenPosition(UDim2.new(0.5, 0, 0.5, H),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,T,false,function()
-- 			t:Destroy()
-- 		end)
-- 	end
-- 	--self:NewShow(text,tc,ts,pos,dlt)
-- end

function M.OnShow(self,text,tc,ts,pos,dlt,image)--tc,ts,pos,dlt 颜色，大小，位置 显示时间
	--textLabel默认值
	local tPos = UDim2.new(0.5,0,0.8,0)
	local anchor = Vector2.new(0.5,0.5)
	local tSize = UDim2.new(0.75,0,0.08,0)
	local textLabel = Instance.new("TextLabel")
	--lable属性
	textLabel.Parent = self.main_inst
	textLabel.AnchorPoint = anchor
	textLabel.Position = tPos
	textLabel.Size = tSize
	textLabel.TextScaled = true
	--文本属性
	textLabel.Text = text 
	textLabel.BackgroundTransparency = 1
	textLabel.TextStrokeTransparency = 0
	textLabel.TextTransparency = 1
	textLabel.RichText = true
	--color
	if tc then		
		--print(typeof(tc),tc)
		if typeof(tc)=="table" then
			textLabel.TextColor3=Color3.new(tc[1],tc[2],tc[3])
		else
			textLabel.TextColor3=tc
		end

	else
		textLabel.TextColor3=TextColor3
	end
	--size
	if ts then
		textLabel.TextSize=ts
	else
		textLabel.TextSize=TextSize
	end
	--position
	if pos then
		local sp=workspace.CurrentCamera:WorldToScreenPoint(pos)
		textLabel.Position=UDim2.new(0,sp.X,0,sp.Y)
		local dt=DT
		if dlt then
			dt=dlt
		end
		delay(dt,function()
			textLabel:Destroy()
		end)
		return
	end
	--移动已有textLabel的距离参数
	local moveOffset = UDim2.new(0, 0, -0.1, 0) 
	local tweenPlaySpeed = 0.3
	local tweenCloseSpeed = 0.2
	textLabel.Size = tSize + UDim2.new(-0.2,0,-0.02,0)
	local showData = {
		Size = tSize,
		TextTransparency = 0
	}
	local closeData = {
		Size = UDim2.new(0.4,0,0.03,0),
		TextTransparency = 0.8
	}

	self:MoveTip(textLabel,moveOffset)
	self.TweenTip(textLabel,tweenPlaySpeed,tweenCloseSpeed,showData,closeData)


end

function M.MoveTip(self,textLabel,moveOffset)
	--向上移动已有的textlabel
	for _, child in pairs(self.main_inst:GetChildren()) do
        if child:IsA("TextLabel") and child ~= textLabel then
			local resetPosition = child.Position + moveOffset
			if resetPosition.Y.Scale < 0.1  then
				child.Visible = false
			end
			child.Position = resetPosition
        end
    end
end

function M.TweenTip(textLabel,tweenPlaySpeed,tweenCloseSpeed,showData,closeData)
	--showInfo
	local tweenInfo = TweenInfo.new(tweenPlaySpeed,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
	local tw = TweenService:Create(textLabel,tweenInfo,showData)

	--closeInfo
	local tweenCloseInfo = TweenInfo.new(tweenCloseSpeed,Enum.EasingStyle.Cubic,Enum.EasingDirection.In)
	local twClose = TweenService:Create(textLabel,tweenCloseInfo,closeData)

	tw.Completed:Connect(function()
		delay(DT,function()
			twClose:Play()
		end)
	end)
	twClose.Completed:Connect(function()
		textLabel:Destroy()
	end)
	tw:Play()
end

-------------------------------------------------------------------------------------------
function M.ShowTextAndImage(self,text,image) --文本框有且只有一个，不销毁，可替换文字
	local tip= self.ImageTip:Clone()
	tip.Parent=self.ImageTip.Parent
	tip.Visible=true
	local ImageLabel=ClientOHOH:GetPath_Loop("ImageLabel",tip)
	local TextLabel=ClientOHOH:GetPath_Loop("TextLabel",tip)
	TextLabel.Text=text
	TextLabel.RichText=true
	ImageLabel.Image=image
	tip:TweenPosition(UDim2.new(0.5, 0, 0.5, H),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,T,false,function()
		tip:Destroy()
	end)
end

function M.Show2(self,text,tc,ts,pos,dlt) --文本框有且只有一个，不销毁，可替换文字
	if self.tt then
		self.tt:Cancel()
	end
	if self.dltt then
		self.dltt:Cancel()
	end
	if self.t == nil then
		local t= Instance.new("TextLabel")
		t.Parent=self.main_inst
		t.AnchorPoint=Vector2.new(0.5, 0.5)
		t.Size=UDim2.new(0.85, 0, 0.08, 0)
		t.TextScaled = true
		t.BackgroundTransparency=1
		t.TextStrokeTransparency=0
		self.t = t
	end
	self.t.Position=UDim2.new(0.5, 0, 0.5,OY)
	self.t.Visible = true
	self.t.Text = text
	--print("guid:",text,tc,ts,pos,dlt)
	if tc then		
		--print(typeof(tc),tc)
		if typeof(tc)=="table" then
			self.t.TextColor3=Color3.new(tc[1],tc[2],tc[3])
		else
			self.t.TextColor3=tc
		end

	else
		self.t.TextColor3=TextColor3
	end

	if ts then
		self.t.TextSize=ts
	else
		self.t.TextSize=TextSize
	end

	if pos then
		local sp=workspace.CurrentCamera:WorldToScreenPoint(pos)
		self.t.Position=UDim2.new(0,sp.X,0,sp.Y)
		local dt=DT
		if dlt then
			dt=dlt
		end

		self.dltt = TweenService:Create(self.t, TweenInfo.new(dt), {Position = UDim2.new(0,sp.X,0,sp.Y)})
		self.dltt.Completed:Connect(function()
			self:Hide2()
		end)
		--delay(dt,function()
		--	t:Destroy()
		--end)
	else
		if self.tt then
			--self.tt:Cancel()
		else
			local tinfo = TweenInfo.new(T, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
			self.tt = TweenService:Create(self.t, tinfo, {Position = UDim2.new(0.5, 0, 0.5, H)})
			self.tt.Completed:Connect(function()
				self:Hide2()
			end)
		end
		self.tt:Play()
	end
end

function  M.Hide2(self)
	self.t.Visible = false
end

return  M